/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entreprise;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import mapping.DBService;

/**
 *
 * @author Quoc-Khai
 */
public class ServiceService {
    
    public Service getService(String serviceID){
        Service service=null;
        DBService dbService=new DBService();
        try {
            service=dbService.getService(serviceID);
        } catch (SQLException ex) {
            Logger.getLogger(ServiceService.class.getName()).log(Level.SEVERE, null, ex);
        }
        return service;
    }
    
    public boolean createService(String serviceID, String serviceName, String servicePrice, String serviceDescription){
        DBService dbService = new DBService();
        Service iService = new Service();
        iService.setServiceName(serviceName);
        iService.setServicePrice(servicePrice);
        iService.setServiceDescription(serviceDescription);
        if(dbService.createService(iService)){
            return true;
        }else{
            return false;
        }
    }
    public boolean deleteService(String serviceID){
        DBService dbService = new DBService();
        Service iService = new Service();
        try {
            iService = dbService.getService(serviceID);
        } catch (SQLException ex) {
            Logger.getLogger(ServiceService.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (iService.getServiceID().length() > 0) {
            dbService.deleteService(Integer.parseInt(serviceID));
            return true;
        }
        
        System.out.println("Service not existe!");
        return false;
    }
    public boolean updateService(String serviceID, String serviceName, String servicePrice, String serviceDescription){
        DBService dbService = new DBService();
        Service iService = new Service();
        try {
            iService = dbService.getService(serviceID);
        } catch (SQLException ex) {
            Logger.getLogger(ServiceService.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (iService.getServiceID().length() > 0) {
            iService.setServiceID(serviceID);
            iService.setServiceName(serviceName);
            iService.setServicePrice(servicePrice);
            iService.setServiceDescription(serviceDescription);
            
            dbService.updateService(iService);
            return true;
        }
        
        System.out.println("Service not existe!");
        return false;
    }
    public List<Service> findServices(String serviceName){
        List<Service> services=null;
        return services;
    }
    
    public ArrayList<Service> services(String serviceName,int from, int numberOfRow){
        DBService dbService = new DBService();
        ArrayList<Service> services=dbService.getServices(serviceName,from,numberOfRow);
        return services;
    }

    public int getNumberOfServices(String serviceSearchName) {
        DBService dBService=new DBService();
        return dBService.getNumberOfServices(serviceSearchName);
    }
}
